// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    presentTheme:getApp().globalData.presentTheme,
    themeName:getApp().globalData.presentTheme.lightColor.match(/wux-(\S*)/)[1],
    // articleList:getApp().globalData.showArticleList
    articleList:getApp().globalData.showArticleList
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      articleList:getApp().globalData.showArticleList,
      goodsList:getApp().globalData.goods,
      presentTheme:getApp().globalData.presentTheme,
      themeName:getApp().globalData.presentTheme.lightColor.match(/wux-(\S*)/)[1],
    })
  },
  onConfirm(e){
    console.log(e.detail.value)
    // var RegExp=/[e.detail.value]+/g
    var newList=[];
    const app=getApp()
    var newGoods=[];
    for(var i=0; i<app.globalData.showArticleList.length; i++){
      if((app.globalData.showArticleList[i].subTitle).search(e.detail.value)!=-1){
        newList.push(app.globalData.showArticleList[i]);
        console.log("subTitle",true,app.globalData.showArticleList[i])
        continue
      }
      if((app.globalData.showArticleList[i].title).search(e.detail.value)!=-1){
        newList.push(app.globalData.showArticleList[i]);
        console.log("title",true,app.globalData.showArticleList[i])
        continue
      }
    }
    if(typeof(app.globalData.goods) != "undefined")
    for(var i=0;i<app.globalData.goods.length;i++){
      if((app.globalData.goods[i].product_name).search(e.detail.value)!=-1){
        newGoods.push(app.globalData.goods[i]);
        console.log("product_name",true,app.globalData.goods[i])
        continue
      }
      if((app.globalData.goods[i].suit_skin_type).search(e.detail.value)!=-1){
        newGoods.push(app.globalData.goods[i]);
        console.log("suit_skin_type",true,app.globalData.goods[i])
        continue
      }
      if((app.globalData.goods[i].suit_crowd).search(e.detail.value)!=-1){
        newGoods.push(app.globalData.goods[i]);
        console.log("suit_crowd",true,app.globalData.goods[i])
        continue
      }
    }
    this.setData({
      articleList:newList,
      goodsList:newGoods
    }) 
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  showGoodsDetail(e){
    console.log(e.currentTarget.dataset.goods)
    wx.navigateTo({
      url: '../shop/showDetail/showDetail',
      success:res=>{
        res.eventChannel.emit('goodsInfo',{ data:e.currentTarget.dataset.goods})
      }
    })
  },
  // navToArticle(e){
  //   var pageUrl='/pages/article/readArticle';
  //   var articleid=e.currentTarget.dataset['articleid']
  //   wx.navigateTo({
  //     url: `${pageUrl}?id=${articleid}`,
  //   })
  //  }
})